import { IFeidaoAiBrowserComponent } from '@feidao-factory/atom-web/interfaces';
import get_user_info from '@feidao-factory/atom-web/msg/get-user-info';
import alert from '@feidao-factory/atom-web/msgbox/alert';
import error from '@feidao-factory/atom-web/msgbox/error';
import storage_get from '@feidao-factory/atom-web/storage/get';
import direct from '@feidao-factory/atom-web/url/direct-to';
import query2url from '@feidao-factory/atom-web/url/query2url';

import { productid } from '../../atom/config';

export default async function a012(fd: IFeidaoAiBrowserComponent, ...args: any[]) {
	// 根据usercode获取在线用户信息
	const usercode = storage_get('user_code') as string;
	if (!usercode) {
		await error('请先登录');
		const url = fd.data.url;
		const page_name = url.match(/.*\/((.*?)\.html)/)[1];
		const params = url.includes('?') ? url.substr(url.indexOf('?')) : '';
		const obj = {
			backurl: './' + page_name + params
		};
		direct(query2url(obj, './login.html'));
	} else {
		const res = await get_user_info(productid, usercode, false, false);
		alert(JSON.stringify(res), '服务返回值', '确定');
	}
}
